<?php
require_once dirname(dirname(__FILE__)) .'/core/Cinnamon.php';
require_once dirname(dirname(__FILE__)) .'/core/Installer.php';

$inst = new Installer();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Install | the Cinnamon</title>
<link rel="stylesheet" href="../view/screen.css" type="text/css" media="screen" />
</head>

<body class="dialog">
	<div id="container">
		<div id="header"><span>the Cinnamon</span></div>
		<div class="block">
<?php if ( $inst->isInstalled() && !$inst->isStep(3) ): ?>
			<h1>Already installed!</h1>
			<p>It seems that you have already installed Cinnamon. If you want to reinstall you have to empty your database or change the database prefix in your configuration file (<code>cse-config.php</code>).</p>
<?php elseif ( $inst->isStep(1) ): ?>
			<h1>Welcome</h1>
			<p>Welcome to Cinnamon Installer. If you face any problems during the installation or you have any queries, it may be helpful to read the <a href="http://www.thecinnamon.org/documentation/index.php?title=Installation_Guide" title="Installation Guide | Cinnamon Statistics Engine">Installation Guide</a>. </p>
			<div class="separator"> </div>
			<form action="install.php" method="post">
			<input type="hidden" name="step" value="2"/>
			<p class="buttons" style="margin-top: 20px;"><input type="submit" value="Let&rsquo;s begin! &raquo;"/></p>
			<div class="clear"> </div>
			</form>
		</div>
<?php elseif ( $inst->isStep(2) ): ?>
			<form action="install.php" method="post">
			<input type="hidden" name="step" value="3"/>
			<h1>Configuration</h1>				
<?php if ( $inst->isConfigured() ): ?>
			<p>It seems that you have already configured Cinnamon. Well done!</p>
<?php elseif ( !$inst->isConfigurable() ): ?>
			<p>Unfortunately, Cinnamon is unable to create the configuration file for you. Before proceeding with the installation you should either change the directory permissions or create the configuration file on your own.</p>

			<p class="buttons"><input type="submit" value="Proceed &raquo;" /></p>
			</form>			
<?php else: ?>
			<p>On the first place you should enter your database connection details. If you don&rsquo;t know them or you are not sure about them, please contact your web hosting provider.</p>
				<p><label for="csedb_username">Username:</label> <input type="text" name="csedb_username" id="csedb_username" value=""/></p>
				<p><label for="csedb_password">Password:</label> <input type="password" name="csedb_password" id="csedb_password" value=""/></p>
				<p><label for="csedb_database">Database:</label> <input type="text" name="csedb_database" id="csedb_database" value=""/></p>
				<p><label for="csedb_host">Host:</label> <input type="text" name="csedb_host" id="csedb_host" value="localhost"/></p>
				<p><label for="csedb_prefix">Tables Prefix:</label> <input type="text" name="csedb_prefix" id="csedb_prefix" value="cse_"/></p>	
<?php endif; if ( $inst->isConfigured() || $inst->isConfigurable() ): ?>

			<h1>Email address</h1>
				<p>Please enter your email address. Once the installation is completed, you will receive &ndash; at the specified email address &ndash; an email including your authentication details. Those details will be required each time that you will use Cinnamon, so please double-check your email address before proceed.</p>
				<p><label for="cseauth_email">E-mail:</label> <input type="text" name="cseauth_email" id="cseauth_email" value=""/></p>

				<p class="buttons"><input type="submit" value="Install &raquo;" /></p>
				<div class="clear"> </div>
			</form>
<?php endif; ?>
<?php elseif ( $inst->isStep(3) && $inst->isInstalled() ): ?>
			<h1>Installation completed!</h1>
			<p>Congratulations! The Cinnamon Statistics Engine has been successfully installed at <a href="<?php echo CSEURL; ?>" title="Cinnamon Statitistics Engine"><?php echo CSEURL; ?></a>.</p>
			<p>You can login at <a href="<?php echo CSEURL; ?>/cse-login.php" title="Login at Cinnamon"><?php echo CSEURL; ?>/cse-login.php</a> using the following details:</p>
			<ul>
				<li><strong>Username</strong>: <?php echo $auth->login; ?></li>
				<li><strong>Password</strong>: <?php echo $auth->pass; ?></li>
			</ul>
			<p>All done! Enjoy :) </p>

			<p class="buttons"><button onclick="location.href='<?php echo CSEURL; ?>'">Smell the Cinnamon</button></p>
			<div class="clear"> </div>
<?php endif; ?>		
		</div>
	</div>
</body>
</html>
